package com.comparable;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

public class CustomPartitioner extends Partitioner<FlowBean, Text> {

    @Override
    public int getPartition(FlowBean flowBean, Text text, int i) {
        // 获取手机前三位
        String prePhone = text.toString().substring(0, 3);

        // 定义分区好变量partition，根据prePhone设置分区号
        int partition;

        if ("136".equals(prePhone)) {
            partition = 0;
        } else if ("136".equals(prePhone)) {
            partition = 1;
        } else if ("136".equals(prePhone)) {
            partition = 2;
        } else if ("136".equals(prePhone)) {
            partition = 3;
        } else {
            partition = 4;
        }

        // 最后返回分区号
        return partition;
    }
}
